package com.doit.day01;

import org.apache.commons.lang3.RandomUtils;
import redis.clients.jedis.Jedis;

public class _05_消费者 {
    public static void main(String[] args) throws InterruptedException {
        Jedis jedis = _03_redis的客户端.getJedis();
        while (true){
            //把producer里面的task拿出来，放到缓冲区中
            jedis.rpoplpush("producer","cache");
            if (RandomUtils.nextInt(100,200) %3 == 0){
                //从缓冲去中进行消费
                String task_id = jedis.rpop("cache");
                //将失败的任务放回到缓冲区
                jedis.lpush("cache",task_id);
                System.out.println(task_id+"运行失败了，重新放回到缓冲区.......");
            }else {
                String task_id = jedis.rpop("cache");
                System.out.println(task_id+"运行成功了");
            }
            Thread.sleep(RandomUtils.nextInt(200,400));
        }
    }
}
